package com.turnengine.client.global.announcement.command;

import com.turnengine.client.global.game.enums.GameLevel;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Post Announcement.
 */
public class PostAnnouncement implements IPostAnnouncement {

	/** The command id. */
	public static final short COMMAND_ID = 101;

	/** The login id. */
	private long loginId;
	/** The game level id. */
	private int gameLevelId;
	/** The game level. */
	private GameLevel gameLevel;
	/** The subject. */
	private String subject;
	/** The body. */
	private String body;

	/**
	 * Creates a new Post Announcement.
	 */
	public PostAnnouncement() {
	}

	/**
	 * Creates a new Post Announcement.
	 * @param loginId the login id
	 * @param gameLevelId the game level id
	 * @param gameLevel the game level
	 * @param subject the subject
	 * @param body the body
	 */
	public PostAnnouncement(long loginId, int gameLevelId, GameLevel gameLevel, String subject, String body) {
		setLoginId(loginId);
		setGameLevelId(gameLevelId);
		setGameLevel(gameLevel);
		setSubject(subject);
		setBody(body);
	}

	/**
	 * Creates a new Post Announcement.
	 * @param iPostAnnouncement the i post announcement
	 */
	public PostAnnouncement(IPostAnnouncement iPostAnnouncement) {
		setLoginId(iPostAnnouncement.getLoginId());
		setGameLevelId(iPostAnnouncement.getGameLevelId());
		setGameLevel(iPostAnnouncement.getGameLevel());
		setSubject(iPostAnnouncement.getSubject());
		setBody(iPostAnnouncement.getBody());
	}

	/**
	 * Returns the login id.
	 * @return the login id.
	 */
	public long getLoginId() {
		return loginId;
	}

	/**
	 * Returns the game level id.
	 * @return the game level id.
	 */
	public int getGameLevelId() {
		return gameLevelId;
	}

	/**
	 * Returns the game level.
	 * @return the game level.
	 */
	public GameLevel getGameLevel() {
		return gameLevel;
	}

	/**
	 * Returns the subject.
	 * @return the subject.
	 */
	public String getSubject() {
		return subject;
	}

	/**
	 * Returns the body.
	 * @return the body.
	 */
	public String getBody() {
		return body;
	}

	/**
	 * Sets the login id.
	 * @param loginId the login id to set.
	 */
	public void setLoginId(long loginId) {
		this.loginId = loginId;
	}

	/**
	 * Sets the game level id.
	 * @param gameLevelId the game level id to set.
	 */
	public void setGameLevelId(int gameLevelId) {
		this.gameLevelId = gameLevelId;
	}

	/**
	 * Sets the game level.
	 * @param gameLevel the game level to set.
	 */
	public void setGameLevel(GameLevel gameLevel) {
		if (gameLevel == null) {
			throw new NullPointerException("gameLevel");
		}
		this.gameLevel = gameLevel;
	}

	/**
	 * Sets the subject.
	 * @param subject the subject to set.
	 */
	public void setSubject(String subject) {
		if (subject == null) {
			throw new NullPointerException("subject");
		}
		this.subject = subject;
	}

	/**
	 * Sets the body.
	 * @param body the body to set.
	 */
	public void setBody(String body) {
		if (body == null) {
			throw new NullPointerException("body");
		}
		this.body = body;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(11, 37);
		hash.append(loginId);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof PostAnnouncement) {
			PostAnnouncement compare = (PostAnnouncement) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.loginId, compare.loginId);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IPostAnnouncement compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.loginId, compare.getLoginId());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("loginId", loginId);
		string.append("gameLevelId", gameLevelId);
		if (gameLevel != null) {
			string.append("gameLevel", gameLevel);
		}
		if (subject != null) {
			string.append("subject", subject);
		}
		if (body != null) {
			string.append("body", body);
		}
		return string.toString();
	}

	public short getCommandId() {
		return COMMAND_ID;
	}
}
